﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.Logic;
using Cosmetic.DataEntity;

public partial class CategoryCascadingDropDownTest : System.Web.UI.Page
{
	private CategoryManager m_CategoryManager	= new CategoryManager();
	protected void Page_Load(object sender, EventArgs e)
	{

	}

	protected void Page_LoadComplete(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			Category theProductCategory	= this.m_CategoryManager.GetTopCategryByName(CategoryManager.ETopCategory.Category_L);
			this.CategoryCascadingDropDown3.SelectedCategory = this.m_CategoryManager.GetSubCateogoriesBySupCategory(theProductCategory)[2];
		}

	}

	protected void cbCreateSubcategory_CheckedChanged(object sender, EventArgs e)
	{
		this.pnlMainCategory.Visible		= !this.pnlMainCategory.Visible;
		//((UpdatePanel)FindControl("UpdatePanelMaster")).Update();
	}
	protected void btnInsertCategory_Click(object sender, EventArgs e)
	{
		if (String.IsNullOrEmpty(this.txtNewCategoryName.Text.Trim()))
		{
			this.ltlNeedCategoryName.Visible	= true;
			return;
		}

		Category theSupCategory;
		if (this.cbCreateSubCategory.Checked)
		{
			theSupCategory	= this.ddlNewCategory.SelectedCategory;
		}
		else
		{
			theSupCategory	= this.m_CategoryManager.GetTopCategryByName(CategoryManager.ETopCategory.Category_L);
		}

		if (!this.m_CategoryManager.CheckContains(theSupCategory, this.txtNewCategoryName.Text.Trim()))
		{
			Category theNewCategory		= new Category();
			theNewCategory.CategoryId	= Guid.NewGuid();
			theNewCategory.Name			= this.txtNewCategoryName.Text.Trim();
			theNewCategory.CreateTime	= DateTime.Now;
            theNewCategory.SupCategoryId = theSupCategory.SupCategoryId;
			//theSupCategory.SubCategories.Add(theNewCategory);
			this.m_CategoryManager.Insert(theNewCategory);
			this.CategoryCascadingDropDown4.SelectedCategory	= theNewCategory;
		}
	}
}
